package com.neu.question.controller;

import com.github.pagehelper.PageInfo;
import com.neu.question.beans.HttpResponseEntity;
import com.neu.question.common.Constans;
import com.neu.question.domain.QuestionnaireInfo;
import com.neu.question.domain.Te;
import com.neu.question.service.QuestionnaireInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class QuestionnaireController {

    private final Logger logger = LoggerFactory.getLogger(QuestionnaireController.class);
    @Autowired
    private QuestionnaireInfoService questionnaireService;


    /**
     * 根据相应的数据库名字和 特殊字段的信息 查出问卷中的数据
     *
     * @param time
     * @param sqid
     * @return
     */
    @GetMapping("/tttt/{time}/{sqid}")
    public List<Te> test(@PathVariable("time") String time, @PathVariable("sqid") String sqid) {
        List<Te> li = new ArrayList<>();
        //从数据库中查数据
        li = questionnaireService.queryEndtimeQues(time, sqid);
        return li;
    }

    /**
     * 根据问卷名查询所有问卷
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryAllQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryAllQuestionnaire(@RequestBody Map<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            PageInfo questionnaireEntityList = questionnaireService.queryQuestionnaireInfo(map);
            if (questionnaireEntityList.getList().size() != 0) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setData(questionnaireEntityList);
                responseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setData(null);
                responseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("查询所有问卷异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    /**
     * 根据id查询问卷详细信息
     */
    //queryQuestionnaireAll
    @RequestMapping(value = "/queryQuestionnaireAll", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireAll(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            Map<String, Object> questionnaire = questionnaireService.queryQuestionnaireById(map);
            if (questionnaire != null) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setData(questionnaire);
                responseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setData(null);
                responseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("查询问卷详细信息异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    //modifyQuestionnaire
    //修改问卷详细信息（包括题目）
    @RequestMapping(value = "/modifyQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaire(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            int i = questionnaireService.modifyQuestionnaire(map);
            if (i == 1) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setMessage("修改成功");
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setMessage(Constans.EXIST_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("修改问卷详细信息异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    //modifyQuestionnaireAnswerTotal
    //修改问卷答题总数
    @RequestMapping(value = "/modifyQuestionnaireAnswerTotal", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaireAnswerTotal(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            int i = questionnaireService.modifyQuestionnaireAnswerTotal(map);
            if (i == 1) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setMessage("修改成功");
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setMessage(Constans.EXIST_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("修改问卷答题总数异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    //modifyQuestionnaireBackground
    //修改问卷背景图片
    @RequestMapping(value = "/modifyQuestionnaireBackground", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaireBackground(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            int i = questionnaireService.modifyQuestionnaireBackground(map);
            if (i == 1) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setMessage("修改成功");
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setMessage(Constans.EXIST_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("修改问卷背景图片异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    ///queryQuestionnaireById
    //查询
    @RequestMapping(value = "/queryQuestionnaireById", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireById(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            Map<String, Object> questionnaire = questionnaireService.queryQuestionnaireById(map);
            if (questionnaire != null) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setData(questionnaire);
                responseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setData(null);
                responseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("查询问卷详细信息异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    /**
     * 根据问卷名查询和项目id所有问卷不是本项目的问卷
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryQuestionnaireByNameAndProjectId", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireByNameAndProjectId(@RequestBody Map<String, Object> map) {
        HttpResponseEntity responseEntity = new HttpResponseEntity();
        try {
            PageInfo questionnaireEntityList = questionnaireService.queryQuestionnaireByNameAndProjectid(map);
            if (questionnaireEntityList.getList().size() != 0) {
                responseEntity.setCode(Constans.SUCCESS_CODE);
                responseEntity.setData(questionnaireEntityList);
                responseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                responseEntity.setCode(Constans.EXIST_CODE);
                responseEntity.setData(null);
                responseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.error("查询所有问卷异常>>>>>>>>>>>", e);
            responseEntity.setCode(Constans.EXIST_CODE);
            responseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return responseEntity;
    }

    /**
     * 根据项目id查询对应问卷的信息
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryQuestionnaireListByProjectId", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryProjectList(@RequestBody Map<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        List<Map<String, Object>> list = questionnaireService.queryQuestionnaireListById(map);
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(list);
            httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
        } catch (Exception e) {
            logger.info("addUserInfo 根据项目id查询问卷的基本信息>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.EXIST_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 查询问卷状态
     *
     * @param questionnaireEntity
     * @return
     */
    @RequestMapping(value = "/selectQuestionnaireStatus", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity selectQuestionnaireStatus(
            @RequestBody QuestionnaireInfo questionnaireEntity) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = Integer.parseInt(
                questionnaireService.queryQuestionnaireIsStopStatus(questionnaireEntity.getId()));
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(status);
        } catch (Exception e) {
            logger.info("addUserInfo 查询问卷状态的基本信息>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 取消问卷和项目的关联
     *
     * @param questionnaireEntity
     * @return
     */
    @RequestMapping(value = "/cancelQuestionnaireProject", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity cancelQuestionnaireProject(
            @RequestBody QuestionnaireInfo questionnaireEntity) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        String questionnaireId = questionnaireEntity.getId();
        int status = questionnaireService.cancelQuestionnaireProject(questionnaireId);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.CANCEL_PROJECT_MESSAGE);
            } else if (status == 0) {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addUserInfo 取消问卷和项目的关联>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 建立问卷和项目的关联
     */
    @RequestMapping(value = "/addQuestionnaireProject", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity addQuestionnaireProject(@RequestBody Map<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.addQuestionnaireProject(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.ADD_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addUserInfo 建立问卷和项目的关联>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id删除问卷
     *
     * @param questionnaireEntity
     * @return
     */
    @RequestMapping(value = "/deleteQuestionnaireById", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity deleteQuestionnaireById(
            @RequestBody QuestionnaireInfo questionnaireEntity) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        String questionnaireId = questionnaireEntity.getId();
        int status = questionnaireService.deleteQuestionnaireInfo(questionnaireId);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.DELETE_MESSAGE);
            } else if (status == 0) {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_DELETE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addUserInfo 根据问卷id删除问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据id修改问卷状态
     *
     * @return
     */
    @RequestMapping(value = "/modifyQuestionnaireStatus", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaireStatus(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        String questionnaireId = (String) map.get("id");
        int status = questionnaireService.modifyQuestionnaireStatus(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                //httpResponseEntity.setData(status);
                httpResponseEntity.setMessage(Constans.UPDATE_STATUS_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addUserInfo 根据问卷id删除问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据id修改问卷为过期状态 0
     *
     * @return
     */
    @RequestMapping(value = "/modifyQuestionnaireStatusToZero", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaireStatusToZero(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.modifyQuestionnaireStatusToZero(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                //httpResponseEntity.setData(status);
                httpResponseEntity.setMessage(Constans.UPDATE_STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addUserInfo 根据问卷id删除问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 添加问卷
     */
    @RequestMapping(value = "/addQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity addQuestionnaire(@RequestBody Map<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.addQuestionnaireInfo(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.ADD_MESSAGE);
            } else if (status == 0) {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.NAME_EXIT_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addQuestionnaireInfo 添加问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id修改问卷
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/modifyQuestionnaireInfo", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity modifyQuestionnaireById(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.modifyQuestionnaireInfo(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.UPDATE_MESSAGE);
            } else if (status == 0) {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.NAME_EXIT_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("modifyQuestionnaireInfo 根据问卷id修改问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id查询问卷结束语和context
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryQuestContextEnd", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity getQuestionnaireById(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        Map<String, Object> questionnaire = questionnaireService.queryQuestionnaireEndAndSmsContent(
                map);
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(questionnaire);
            httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
        } catch (Exception e) {
            logger.info(
                    "getQuestionnaireById 根据问卷id查询问卷结束语和context>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 添加发送问卷方式
     */
    //addSendQuestionnaire
    @RequestMapping(value = "/addSendQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity addSendQuestionnaire(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.addSendQuestionnaire(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.ADD_MESSAGE);
            } else if (status == 0) {
                // 邮箱格式错误
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.EMAIL_FORMAT_MESSAGE);
            } else if (status == 2) {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.RELEASE_TIME_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("addSendQuestionnaire 添加发送问卷方式>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 保存问卷结束语和短信内容
     *
     * @param map
     * @return
     */
    //saveSendQuestionnaire
    @RequestMapping(value = "/saveSendQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity saveSendQuestionnaire(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int status = questionnaireService.saveSendQuestionnaire(map);
        try {
            if (status == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.ADD_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.COPY_EXIT_UPDATE_MESSAGE);
            }
        } catch (Exception e) {
            logger.info("saveSendQuestionnaire 保存问卷结束语和短信内容>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 查询所有历史问卷
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryHistoryQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryAllHistoryQuestionnaire(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        List<Map<String, Object>> questionnaire = questionnaireService.queryHistoryQuestionnaire(
                map);
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(questionnaire);
            httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
        } catch (Exception e) {
            logger.info(
                    "queryAllHistoryQuestionnaire 查询所有历史问卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 批量添加答卷
     *
     * @param map
     */
    @RequestMapping(value = "/addAnswerQuestionnaire", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity addAnswerQuestionnaire(@RequestBody Map<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        //将map放入list中
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(map);
        String result = questionnaireService.addAnswerQuestionnaire(list);
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);
            httpResponseEntity.setMessage(Constans.ADD_MESSAGE);
        } catch (Exception e) {
            logger.info(
                    "addAnswerQuestionnaire 批量添加答卷>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 查询此人名下所有问卷名称和id
     */
    @RequestMapping(value = "/queryAllQuestionnaireByCreated", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryAllQuestionnaireByCreated(@RequestBody Map<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        //传回来的是用户id
        List<Map<String, Object>> questionnaire = questionnaireService.queryAllQuestionnaireByCreated(map);
        try {
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(questionnaire);
            httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
        } catch (Exception e) {
            logger.info(
                    "queryAllQuestionnaireByCreated 查询所有问卷名称>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 模糊查询所有学校统计表
     */
    @RequestMapping(value = "/queryQuestionnaireAboutSchool", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireAboutSchool(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        PageInfo questionnaire = questionnaireService.queryQuestionnaireAboutSchool(map);
        try {
            if (questionnaire != null) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setData(questionnaire);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }

        } catch (Exception e) {
            logger.info(
                    "queryQuestionnaireAboutSchool 查询所有学校统计表>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id查询该问卷的答卷收集数据汇总（查询学校统计表）
     *
     * @param map 问卷id
     */
    @RequestMapping(value = "/queryQuestionnaireCount", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireCount(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        Map<String, Object> answerData = questionnaireService.queryQuestionnaireCount(map);
        try {
            if (answerData != null) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setData(answerData);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.info(
                    "queryQuestionnaireCount 根据问卷id查询该问卷的答卷收集数据汇总>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id查询该问卷的所有答卷收集数据（查询答卷表）
     *
     * @param map 问卷id
     */
    //queryRecordCountAnswer
    @RequestMapping(value = "/queryRecordCountAnswer", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryRecordCountAnswer(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        PageInfo answerData = questionnaireService.queryRecordCountAnswer(map);
        try {
            if (answerData != null) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setData(answerData);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.info(
                    "queryRecordCountAnswer 根据问卷id查询该问卷的所有答卷收集数据>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * queryQuestionnaireTitle
     * 根据问卷id获取问卷题目标题和题目类型
     *
     * @param map 问卷id
     */
    @RequestMapping(value = "/queryQuestionnaireQuestionTitle", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity queryQuestionnaireTitle(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        Map<String, Object> answerData = questionnaireService.queryQuestionnaireQuestionTitle(map);
        try {
            if (answerData != null) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setData(answerData);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.info(
                    "queryQuestionnaireTitle 根据问卷id获取问卷题目标题和题目类型>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id查询该答卷的答案统计细节
     * selectRecordAnswerDetail
     *
     * @param map 问卷id
     */
    @RequestMapping(value = "/selectRecordAnswerDetail", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity selectRecordAnswerDetail(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        List<Map<String, Object>> answerData = questionnaireService.selectRecordAnswerDetail(map);
        try {
            if (answerData != null) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setData(answerData);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setData(null);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.info(
                    "selectRecordAnswerDetail 根据问卷id查询该答卷的答案统计细节>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据问卷id追加问卷题目
     * selectRecordAnswerDetail
     *
     * @param map 问卷id
     */
    @RequestMapping(value = "/addQuestionnaireQuestion", method = RequestMethod.POST,
            headers = "Accept=application/json")
    public HttpResponseEntity addQuestionnaireQuestion(@RequestBody HashMap<String, Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        int answerData = questionnaireService.modifyQuestionnaireQuestion(map);
        try {
            if (answerData == 1) {
                httpResponseEntity.setCode(Constans.SUCCESS_CODE);
                httpResponseEntity.setMessage(Constans.STATUS_MESSAGE);
            } else {
                httpResponseEntity.setCode(Constans.EXIST_CODE);
                httpResponseEntity.setData(null);
                httpResponseEntity.setMessage(Constans.QUERYFAIL_MESSAGE);
            }
        } catch (Exception e) {
            logger.info(
                    "addQuestionnaireQuestion 根据问卷id追加问卷题目>>>>>>>>>>>" + e.getLocalizedMessage());
            httpResponseEntity.setCode(Constans.LOGOUT_NO_CODE);
            httpResponseEntity.setMessage(Constans.EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

}
